﻿using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace Medicalsystem.MCP.FormDesigner.Property
{
    /// <summary>
    /// 获取模板属性
    /// </summary>
    public class GetModelProperty : GetProperty
    {
        /// <summary>
        /// 模板窗体
        /// </summary>
        /// <param name="Form"></param>
        public GetModelProperty(ModelDesign modelDesign)
            : base(modelDesign.ModelForm as Control)
        {
            this._form = modelDesign.ModelForm;
            this._model = modelDesign;
        }

        /// <summary>
        /// 关联的模板
        /// </summary>
        private System.Windows.Forms.Form _form;

        /// <summary>
        /// 模板设计时
        /// </summary>
        private ModelDesign _model;

        /// <summary>
        /// 文本
        /// </summary>
        [CategoryAttribute("外观")]
        [ShowChinese("标题")]
        [Description("显示标题")]
        [EditorAttribute(typeof(ContentEditorDropDown), typeof(System.Drawing.Design.UITypeEditor))]
        public string Text
        {
            get
            {
                return this._form.Text;
            }
            set
            {
                this._form.Text = value;
            }
        }

        /// <summary>
        /// 宽度-是对容器窗体的设置
        /// </summary>
        [CategoryAttribute("布局")]
        [ShowChinese("宽度")]
        [Description("控件宽度")]
        public int Width
        {
            get { return this._form.Width; }
            set
            {
                this._form.Width = value;
            }
        }

        /// <summary>
        /// 高度-时对容器窗体的设置
        /// </summary>
        [CategoryAttribute("布局")]
        [ShowChinese("高度")]
        [Description("控件高度")]
        public int Height
        {
            get { return this._form.Height; }
            set
            {
                this._form.Height = value;
            }
        }

        /// <summary>
        /// 自动滚动
        /// </summary>
        [CategoryAttribute("布局")]
        [ShowChinese("自动滚动")]
        [Description("指示当控件内容大于它的可见区域时是否自动显示滚动条")]
        public bool AutoScroll
        {
            get
            {
                return _form.AutoScroll;
            }
            set
            {
                this._form.AutoScroll = value;
            }
        }

        /// <summary>
        /// 背景颜色
        /// </summary>
        [CategoryAttribute("外观")]
        [ShowChinese("背景颜色")]
        [Description("背景颜色")]
        public Color BackColor
        {
            get
            {
                return _form.BackColor;
            }
            set
            {
                _form.BackColor = value;
            }
        }

        /// <summary>
        /// 背景图像
        /// </summary>
        [CategoryAttribute("外观")]
        [ShowChinese("背景图像")]
        [Description("用于该窗体的背景图像")]
        public Image BackgroundImage
        {
            get
            {
                return _form.BackgroundImage;
            }
            set
            {
                if (value != null)
                {
                    System.IO.MemoryStream ImageMem = new System.IO.MemoryStream();
                    value.Save(ImageMem, value.RawFormat);

                    if (ImageMem.Length > 524288)
                    {
                        MessageBox.Show("请选择小于512KB的图片资源", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        _form.BackgroundImage = value;
                    }
                }
                else
                {
                    _form.BackgroundImage = value;
                }
            }
        }

        /// <summary>
        /// 图像布局
        /// </summary>
        [CategoryAttribute("外观")]
        [ShowChinese("图像布局")]
        [Description("用于组件的背景图像布局")]
        public ImageLayout BackgroundImageLayout
        {
            get
            {
                return _form.BackgroundImageLayout;
            }
            set
            {
                _form.BackgroundImageLayout = value;
            }
        }

        /// <summary>
        /// 允许改变尺寸
        /// </summary>
        [CategoryAttribute("行为")]
        [ShowChinese("允许改变尺寸")]
        [Description("是否允许改变窗体大小")]
        public bool ChangeSize
        {
            get
            {
                return _form.MaximizeBox;
            }
            set
            {
                _form.MaximizeBox = value;
                _form.MinimizeBox = value;
            }
        }
    }
}